//枚举类型
public enum Enum {
    RED(1, "红色"),
    GREEN(2, "绿色"),
    BLACK(3,"黑色");
    private int ordinal;
    private String color;

    Enum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        //values()以数组形势返回枚举类型所有成员
        Enum[] enums = Enum.values();

        //ordinal() 获取枚举成员的索引位置
        for(int i = 0; i < enums.length; i++)
        {
            System.out.println(enums[i].ordinal);
        }

        //valueOf 将普通字符串转为枚举类型
        System.out.println(Enum.valueOf("BLACK"));

        //compareTo 比较两个枚举成员在定义时的顺序
        System.out.println(RED.compareTo(BLACK));
    }
    public static void main1(String[] args) {
        Enum  color = RED;
        switch(color) {
            case GREEN:
                System.out.println("GREEN");
                break;
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            default:
                System.out.println("error");
                break;
        }
    }
}
